using System;
using System.Collections.Generic;
using System.Text;
using MoEngine;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace MoGameLib
{
    public class WindowBoard : Window
    {
        public WindowBoard(WindowBase parent)
            : base(parent)
        {
            m_Viewport = MasterWnd.Device.Viewport;
        }

        protected Viewport m_Viewport;
        public Viewport Viewport
        {
            get { return m_Viewport; }
        }

        protected IBoard m_Board;
        public IBoard Board
        {
            get { return m_Board; }
            set { m_Board = value; }
        }

        protected Camera2D m_Camera;

        protected override void OnLayoutValidated()
        {
            base.OnLayoutValidated();

            m_Viewport.X = (int)GlobalPosition.X;
            m_Viewport.Y = (int)GlobalPosition.Y;
            // TODO: clamp size to current display resolution
            m_Viewport.Width = (int)Size.X;
            m_Viewport.Height = (int)Size.Y;

            m_Camera.ViewportSize = new Point(m_Viewport.Width, m_Viewport.Height);

            m_Camera.Center = new Vector3(m_Viewport.Width/2, m_Viewport.Height/2, 0);
        }

        protected override void DrawWindow(GameTime time)
        {
            if (m_Board != null && m_Camera != null)
            {
                Viewport defaultViewport = MasterWnd.Device.Viewport;

                MasterWnd.Device.Viewport = m_Viewport;


                m_Board.Render(m_Camera);

                MasterWnd.Device.Viewport = defaultViewport;
            }

            base.DrawWindow(time);
        }
    }
}
